Hi.
Welcome to the next section of scripting.
Okay.
Thing, and you can apply that in lots of different areas already.
Um, in this section, while I will be teaching you new concepts, which you'll be using commonly in
scripting, the majority of it, um, are just new applications of what you already know.
Um, so, for example, you don't know at the moment how to make a game pass or how to cast a ray,
for example.
These are small things, but you can apply to the scripting you already know, because taking what you
already know and just really building upon it.
Okay.
Um, so to start off with today we're going to have we're going to revisit some of the data types we
looked at now right at the start.
Um, we looked at data types for your vector threes, brick colors, all that kind of stuff.
Okay.
And there were some things I skipped out when I taught you that.
The reason why obviously is because that was most likely one of your first lessons scripting.
And I can't kind of put all this onto you at once.
Um, so there are a couple of things which I'm going to kind of say.
What I told you in the last section is kind of a truth, but it's kind of not the truth at the same
time, basically.
Um, just so it made it simpler when you were learning, basically.
Okay.
Um, so add a script into the workspace.
Okay.
So the first the first datatype we're going to revisit are strings.
Now obviously strings are quite simple.
You use your speech marks.
You can write text in here like that for whatever text you want to write.
Just goes in there.
Um, there are some things, though to do with strings, which I think are quite important.
Now you using strings is usually quite difficult, actually.
Um, you shouldn't really be using a string unless you want to, to store data or things like that,
or if you need, if it's required.
Um, because they're kind of like a very dead end thing.
You can't do many things with strings.
Um, you can't really you can't take away words in the middle of a string.
It's very difficult to do things with a string, basically.
Um, but I do want to show you a couple functions.
Allow you to do some things with a string at least.
But yeah, usually with strings, they're a bit difficult to do things with, as they're kind of like
a very dead end thing.
You can't really, um, adjust the text.
You've written too much.
Um, but the stuff you can do, you can access using the string function like this here.
And this provides a bunch of functions to manipulate strings.
It says there or just to change something to do with strings basically.
Okay.
So string dots and we have all of these options here.
Now like with most things I'm not going to show you all of these.
I'm going to show you the ones which I think are the most useful.
But feel free to have a look at some of the other ones as well after this lesson.
Okay, so the first one I want to show you is string dot lower and what string dot lower is.
It takes your string and converts any uppercase letters into lowercase letters.
Now.
Sounds amazing right?
Very interesting.
Um, not.
But the reason why this can be very useful is if you want to get input from the player in the form of
text, it can be very difficult to handle that.
Let's say for example, um, you want to um, delete, you want you have a pet.
Okay.
Did he progress and restart?
Okay.
Um, and to confirm this, the player needs to type in, confirm.
Okay, into the text box in order for this to work.
Well, they could write confirm like that there.
They could write confirm.
They could even write confirm or any of these other options.
Now instead of going through and saying if they write this or if they write it as an uppercase, it
is confirmed with an with a lowercase n or anything like that.
Instead, you can use a string dot lower to basically ignore any any.
Turned to lowercase.
So no matter what format the player writes it in, this is going to convert it to confirm if they write
that if they write that out.
Okay.
I've also seen some games where you have to like guess the logo and the player types in the logo, and
if it's correct, then they go through for example there's another use.
If it shouldn't, they shouldn't get it wrong.
If they put if they write it all in uppercase or all in lowercase or with an uppercase letter to start
with, it makes sense.
Okay, so this writing just writing through here, what makes it a lot easier to work with.
So I could say, um, my string.
Like that's fair.
And if I was just to print this using the print function.
And remember, I'm not going to be using the speech marks for this print function because this here
is a string already.
I don't need to string a string if that makes sense.
And if I was to, it would be printing this text, not the value of this code.
Okay, let's run the game.
And take a look in the outputs.
And yeah, my string is printed all in lowercase there.
So.
Well that's not too interesting.
It is very useful.
Okay.
Another one which I think is very useful um, is string dot Len or string dot Len.
Okay.
This one will return the length of your string.
This one's very useful as well.
Let's say you want the player to be able to name a pet.
They have for example.
Okay, um, nothing will stop the player from naming the part a really.
So naming naming, naming the pet a really long name, like 100, 150 characters.
Um.
And it wouldn't display correctly on your GIS, and it just would make it look a bit weird.
You can prevent this by checking the length of the string and only allowing a certain amount of characters.
Let's say 30 characters, for example.
So you could use this in an if statement and say if string Len, the player's string is entered is bigger,
even bigger than 30, then return something that basically says, you know, you can't do this.
Pick another one that's less, that has less characters in it.
Okay.
So again, you can put in whatever string in there and it will then output the amount of letters okay.
Spaces as well will be included.
Any kind of characters in that would be included okay.
As said earlier, there are lots of other functions to do with string here.
Um, now some of these are more useful than others, but I can assure you, the two that I showed you
there, I think are the most useful.
But feel free to take a look at some of the other ones as well if you are interested.
But these are the only two that I've found useful through my time scripting.
Okay, okay, the next few are to do a vector three.
Okay, now um, vector three is a way to change properties that have three numbers in them an x, y,
and z.
And we use it to basically say basically say um, the first number here is the x value, the second
is the y and the third is the z.
And to do that we say vector three dot new and type in our three numbers like that there.
However, there are other ways to use vector three.
You don't have to necessarily say dot new all of a time.
Okay.
When I first taught you this, I said, oh yeah, you just you use you just use dot new.
The reason why is because dot new is the simplest one.
Um, whereas there are other ones you can other methods you can use which might be quicker.
So vector three dots.
We have all of these other options that you can choose from here.
Okay.
Now first I want to show you vector 3.0 and vector 3.1.
Vector 3.0 basically has the value of zero comma zero comma zero.
So if you ever want to set something to be 000, instead of writing out vector three dot new brackets
000 and there being room for mistake in there, you can just very simply write vector 3.0 instead,
and it will have the value of that there.
Same thing with vector 3.1.
It's the same kind of thing.
It has a value there of one comma, one comma, one like that there.
Alternatively, if you wanted to give it the value of, let's say ten, ten, ten, what you could do
is go for vector 3.1 and then times that by ten, your times each number by ten.
She would then get ten by ten by ten like that.
So basically any time you want all three numbers to be the same, it might be quicker to write out using
vector 3.1 and then times it by certain amount.
Okay.
So just an idea there.
You might want to use the other thing I want to show you to do vector three is you can also do this
just for one axis.
So if you if you're only wanting to change one axis you can write this as well.
So vector three dot x axis sorry x axis for example has the value of one comma zero comma zero the same
as well.
If you took y axis at zero, one, zero and z axis, it's 001.
Okay.
Um, and same kind of thing as well.
You can times this by seven for example.
And that would give you the value of 700.
So just some different options really for you to pick from when you are using vector threes.
Do I use them.
Not particularly.
Um there are some cases where they've been better to use because it basically means that well, by using
vector 3.1 and timing it by a number, it means that it's impossible for two of the numbers to be different.
For example, if that is the case, you're wanting to do.
But there are some uses of them.
But I think, um, again, you might not use them all the time, but it's worth knowing about just some
extra things you might want to know about, and it also could save you a bit of time summing them as
well.
Okay, cool.
On to the next one.
I want to show you a bit more about which are which is color three.
Okay, now color three.
I lied to you a bit on color three.
I'll be honest.
Um, I did lie to you a couple of times when I was teaching.
Not because I didn't know what I was doing, but just because if I told you the truth, I guess, um,
or the the complete.
The complete idea of the concept was I was telling you about.
Um, you just wouldn't have understood it because, you know, it was I did I did it for people who
were just starting to learn, you know?
Um, but when we write color three dot new and we type in our numbers here, this technically is not
is not a RGB value.
We're writing inside of here because RGB is from 0 to 255.
But in this case we're only writing 0 to 1.
If I wrote two, it means the same as one.
See the same color in that case.
Okay.
Um, so how can we put in a color three on a color three a vector, three on a vector three a RGB value.
Because there's quite annoying if you want a specific color.
So let's add a let's say we want a specific color.
We want this exact color here.
You can't write in it properly.
It's difficult to do that.
But there is a method to do that which is to instead of taking nu to write dot from RGB.
And this allows you to write in the RGB component.
So 163 comma 162 comma 165 would give that exact color there.
So if you are wanting an exact color in RGB format, you'd want to use dot from RGB like that there.
Okay.
Um, you can also repeat this for other types for other color types.
So instead of RGB you might also heard of hex as well.
Hex is a type, is A is a way of naming colors similar to RGB, but it uses hex code hex codes basically.
And if you have one of these hex codes you want to use, you could write down color free from hex and
write it in there as a string, or of course as the alternative HSV, which is another way of using
colors which you can write in there as well.
Do I use them?
Not particularly, but from RGB?
I do definitely use quite a lot.
So, um, yeah.
Okay.
Um, the next one I think is, um, probably one of the largest lies I've told you, um, to do with
this, which is to do a brick color.
Okay.
Now, um, when we're writing brick color, you may or may not noticed when we say brick color new.
And put a pair of brackets in here, it says to write the value as a number.
But I told you to write it as a string.
And when you put in the speech marks it, sometimes it converts it to a string and now thinks you're
writing a string and you write a string in there.
So why did it originally say number when you can when when I'm telling you to write a string in?
Well, basically brick color is a bit more advanced than I first explained it to be.
Um, brick color basically uses a brick color index.
Now, if you want to find this index, I would suggest you do this.
Actually go on to Google, search up Roblox Studio Brick Color Index and it will give you the entire
index with each color.
So each possible each possible color you could pick from has its own ID so its own ID, which is which
is a number.
Okay.
And there's actually a lot more colors than our first listed in this palette.
This palette only contains about 100, perhaps 70 around that kind of number.
Um, the brick color index contains hundreds.
Okay.
So you can make so you can use the index if you wanted to and type in a number.
Um, I'm not sure exactly what all these numbers mean.
And they don't go up linearly.
Linearly.
So it's not like 1234, five.
I don't believe there's a six or a seven, for example.
It doesn't go up in um, one in in normal counting numbers it goes up a bit strangely.
So um, basically, unless you're going to remember the number for, um, for each, for each color,
there's no point writing in here, each number, each the brick color ID, okay.
And it says, yeah, it says here actually constructs a brick color from its numerical index, which
is the index I'm talking I'm talking about here.
Okay.
Um, what I recommend using the index.
Absolutely not.
Okay.
Um, it's so much easier to write a string in, um, and to just pick your, pick your color here.
And all the colors are listed here, but you can choose from.
So even though they have their own IDs, I don't really recommend using it.
And how brick actually actually works is that it gets the string.
It then finds the ID relevant to that string and then assigns it the ID basically.
Okay, so a bit more advanced than I first explained.
But again, if I started talking about indexes and stuff when you first were learning about a brick
color data type, you were being very confused.
Which is why sometimes, um, when it's not just in not just in coding, but also just in subjects in
general, advanced subjects like maths or science, you obviously aren't.
You sometimes aren't told the complete truth just for sake of explanation.
But when you do, um, learn a bit more, an advanced way, there are some more things which you kind
of see that that was the truth, but it wasn't the entire truth.
Okay.
Um, but yeah, that's Brooklyn dot new.
You can use numbers for it, basically.
Okay.
There's also two other options to do a brick color, which is a brick color dot random like this here,
this will pick a random brick color, which is really cool if you're wanting to randomize colors and
things like that.
Maybe you want to add a team and you don't mind what color the team is.
Make it a random color.
Or um, maybe you have a color block game.
I've seen a quite a few of those where you have to sand on a certain color.
You could pick a random color to use that method as well.
And alternatively, you can also use brick color palette which instead of.
Using the brick color index.
It uses the palette index, which basically its position on his palette table here.
However, use this.
No.
Is it really useful?
Not particularly.
But it's there if you want to use it.
I'm also seeing some scripting scripting applications with it as well.
If you want the player to be able to pick a brick color and you give them this palette here, and you
can then pick which which one they picked and assign it to a palette index.
It's possible that way, but it's still you were worth you knowing about.
Okay.
And the final extra bit I want to teach you about is do of enums.
So we already know a bit about enums, um, how enums stores all the lists.
You then pick an entry, you can even pick a list you want to use and then the entry from that list.
Okay.
Um, one thing you can't do with enums that you can do for basically any other data type is randomize.
It.
You can randomize colors by using Math.random.
Um, you can do Vector3 by Math.random.
You could do randomize a string.
Be a bit tedious, but you could do and any and any other stuff.
But you can't really randomize an enum because it's a list based.
Um, or it'd be a bit more difficult to do so.
Um, but luckily there is a handy option called dot.
Um, is it colon?
Yeah it's colon.
Sorry about that.
Called colon.
Get enum items and this function will return all of the items in this table.
So it will return an asphalt basalt brick cobblestone concrete coated metal and so on okay.
So then you could go through this and perhaps you could you can use a for comma and say um for I comma
v in pairs enum dot material colon get enum items do.
You could then pick a random number.
So let's say Math.random one two.
The number in this here.
And basically say, if I is equal to the random number up here, then that's the one that's selected.
So it just gives you the application of being able to select random results from an enum value.
Okay.
So these are all of the ones here I wanted to explain.
Of course there are lots more with all these different data types, but um, I don't want to get into
the habit of explaining to you every single possible thing that you could know, because there's no
point on doing that if you're never going to use it.
Um, the stuff I'm showing you is only stuff that I think could possibly be useful for you.
Like this.
Um, the main uses of these ones, I think, are vector 3.0 and one are pretty cool.
Um, from RGB is also pretty cool.
Um, the random is used quite a bit as well, and I've also used the material and the string ones as
well before, so quite a few uses there.
Quite a lot of stuff you need to be aware of, and hopefully also it's given you a bit of a better understanding
about some of these data types as well.
Okay, so hope you enjoyed this one and learning a bit more and learning about where kind of, um,
didn't tell you the entire truth when learning.
I promise you haven't done that for, um, anything else that I can think of.
So yeah.
Okay.
And you can join me in the next lecture where we're going to have a look at one of our first new services
called Tween Service.
So join me for that one.